#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
#define maxn 110
#define inf 0x3fffffff
int n, u, v, w;
struct node
{
    int val, lchild, rchild;
};
node tree[maxn];
int dis[maxn][maxn];
int MINCost = inf;
int main()
{
    cin >> n;
    fill(dis[0], dis[0] + maxn * maxn, inf);
    for (int i = 1; i <= n; ++i)
    {
        cin >> w >> u >> v;
        tree[i].val = w;
        tree[i].lchild = u;
        tree[i].rchild = v;
        dis[i][u] = dis[i][v] = dis[u][i] = dis[v][i] = 1;
        dis[i][i] = 0;
    }
    for (int k = 1; k <= n; ++k)
    {
        for (int i = 1; i <= n; ++i)
        {
            for (int j = 1; j <= n; ++j)
            {
                dis[i][j] = min(dis[i][k] + dis[k][j], dis[i][j]);
            }
        }
    }
    for (int i = 1, cost = 0; i <= n; ++i)
    {
        cost = 0;
        for (int j = 1; j <= n; ++j)
        {
            cost += dis[i][j] * tree[j].val;
        }
        MINCost = min(cost, MINCost);
    }
    cout << MINCost;
    return 0;
}